<!DOCTYPE html>
<html lang="en" data-ng-app="App">

<head>
    <meta charset="UTF-8">
    <title>云图轨道交通数据管理系统-账号申请</title>
    <link rel="stylesheet" href="http://cdn.staticfile.org/font-awesome/4.2.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/authenticateResources/style.css">
</head>


<body data-ng-controller="homeCtrl">
    <div id="register-container" style="top:15%">
        <div id="sgidi">
            最后一步
        </div>
        <div class="divider"></div>
        <div class="form-wrapper" id="form-wrapper">
            <form action="/register2" method="post" enctype="application/x-www-form-urlencoded">
                <div class="input-section">
                    <label for="corporation">
                        单位 <i class="fa fa-university"></i>
                    </label>
                    <select data-ng-options="c.name for c in corporationList" data-ng-model="corporation"></select>
                    <input type="hidden" name="corporation" value="{{corporation.shortName}}">
                </div>
                <div class="input-section">
                    <label for="department">
                        部门 <i class="fa fa-sitemap"></i>
                    </label>
                    <select data-ng-options="c.name for c in corporation.departments" data-ng-model="department"></select>
                    <input type="hidden" name="department" value="{{department.name}}">
                </div>
                <div class="input-section">
                    <label for="reviewer" title="只有审核人通过了你的请求,你的账户才可以使用.">
                        审核人 <i class="fa fa-male"></i>
                    </label>
                    <select data-ng-model="reviewer" required data-ng-options="p for p in department.admins"></select>
                    <input type="hidden" name="reviewer" value="{{reviewer}}">
                </div>
                <div class="input-section">
                    <label for="realName">
                        真实姓名 <i class="fa fa-user-md"></i>
                    </label>
                    <input type="text" name="realName" data-ng-model="realName" required placeholder="审核人需要知道你的名字">
                </div>
                <div class="input-section">
                    <label for="phone">
                        电话 <i class="fa fa-phone"></i>
                    </label>
                    <input type="text" name="phone" data-ng-model="phone" required placeholder="手机号码">
                </div>
                <div class="input-section">
                    <label for="mail">
                        电子邮箱 <i class="fa  fa-envelope"></i>
                    </label>
                    <input type="text" name="mail" data-ng-model="mail" required placeholder="邮箱">
                </div>
                <div class="input-section" style="text-align:center;">
                    <input type="radio" name="sendMail" checked style="width:auto;margin-top:5px; vertical-align:middle;" value="true" />
                    <span style=" vertical-align:middle;letter-spacing:1px;">同时发邮件,提醒审核人</span>
                    <input type="radio" name="sendMail" style="width:auto;margin-top:5px; vertical-align:middle;" value="false" />
                    <span style=" vertical-align:middle;letter-spacing:1px;">不发送邮件,我能耐心等待</span>
                </div>
                <input type="hidden" name="userName" value="{{userName}}">
                <input type="hidden" name="password" value="{{password}}">
                <div class="input-section">
                    <label>
                        &nbsp;
                    </label>
                    <input type="submit" class="submit-btn finish" value="完成" data-ng-click="submit($event)">
                </div>
            </form>
        </div>
    </div>
    <footer>©2014-2015 上海岩土工程勘察设计研究院有限公司-地理信息所版权所有</footer>
</body>
<script src="http://cdn.staticfile.org/angular.js/1.3.0-beta.13/angular.min.js"></script>
<script>
var app = angular.module('App', []);
app.controller('homeCtrl', ['$scope', '$timeout', '$http', function($scope, $timeout, $http) {
    //初始化为空 
    var getCorporationList = function() {
        $http({
            method: 'get',
            url: '/register2/corporation'
        }).success(function(data) {
            $scope.corporationList = data;
        });
    };
    getCorporationList();

    var shake = (function() {
        var shakeRun = false;

        function shake() {
            if (shakeRun) return;
            var loginBtn = document.getElementById('form-wrapper');
            shakeRun = true;
            angular.element(loginBtn).addClass('shake');
            $timeout(function() {
                shakeRun = false;
                angular.element(loginBtn).removeClass('shake');
            }, 800);
        };
        return shake;
    })();

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }

    $scope.realName = "";
    $scope.userName = decodeURIComponent(readCookie('username')) || "";
    $scope.password = decodeURIComponent(readCookie('password')) || "";



    $scope.submit = function(event) {
        if ($scope.corporation && $scope.department && $scope.reviewer && $scope.realName && $scope.phone && $scope.mail) {
            alert('请求已发送,请等待审核');
        } else {
            event.preventDefault();
            shake();
        }
    };

}]);
</script>

</html>
